package com.biosimilarity.reflection.model.paratrope;
import com.biosimilarity.reflection.model.paratrope.Absyn.*;

public class PrettyPrinter
{
  //For certain applications increasing the initial size of the buffer may improve performance.
  private static final int INITIAL_BUFFER_SIZE = 128;
  //You may wish to change the parentheses used in precedence.
  private static final String _L_PAREN = new String("(");
  private static final String _R_PAREN = new String(")");
  //You may wish to change render
  private static void render(String s)
  {
    if (s.equals("{"))
    {
       buf_.append("\n");
       indent();
       buf_.append(s);
       _n_ = _n_ + 2;
       buf_.append("\n");
       indent();
    }
    else if (s.equals("(") || s.equals("["))
       buf_.append(s);
    else if (s.equals(")") || s.equals("]"))
    {
       backup();
       buf_.append(s);
       buf_.append(" ");
    }
    else if (s.equals("}"))
    {
       _n_ = _n_ - 2;
       backup();
       backup();
       buf_.append(s);
       buf_.append("\n");
       indent();
    }
    else if (s.equals(","))
    {
       backup();
       buf_.append(s);
       buf_.append(" ");
    }
    else if (s.equals(";"))
    {
       backup();
       buf_.append(s);
       buf_.append("\n");
       indent();
    }
    else if (s.equals("")) return;
    else
    {
       buf_.append(s);
       buf_.append(" ");
    }
  }


  //  print and show methods are defined for each category.
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExpr foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExpr foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.Abstraction foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.Abstraction foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.Concretion foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.Concretion foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.Nominal foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.Nominal foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.Formals foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.Formals foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.Actuals foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.Actuals foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExprPlus foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExprPlus foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.ListProcessExprPlus foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.ListProcessExprPlus foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String print(com.biosimilarity.reflection.model.paratrope.Absyn.ListNominal foo)
  {
    pp(foo, 0);
    trim();
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  public static String show(com.biosimilarity.reflection.model.paratrope.Absyn.ListNominal foo)
  {
    sh(foo);
    String temp = buf_.toString();
    buf_.delete(0,buf_.length());
    return temp;
  }
  /***   You shouldn't need to change anything beyond this point.   ***/

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExpr foo, int _i_)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Composition)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Composition _composition = (com.biosimilarity.reflection.model.paratrope.Absyn.Composition) foo;
       if (_i_ > 0) render(_L_PAREN);
       render("{");
       pp(_composition.listprocessexpr_, 1);
       render("}");
       if (_i_ > 0) render(_R_PAREN);
    }
    else     if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Reception)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Reception _reception = (com.biosimilarity.reflection.model.paratrope.Absyn.Reception) foo;
       if (_i_ > 1) render(_L_PAREN);
       pp(_reception.nominal_, 0);
       render("?");
       pp(_reception.abstraction_, 0);
       if (_i_ > 1) render(_R_PAREN);
    }
    else     if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Transmission)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Transmission _transmission = (com.biosimilarity.reflection.model.paratrope.Absyn.Transmission) foo;
       if (_i_ > 1) render(_L_PAREN);
       pp(_transmission.nominal_, 0);
       render("!");
       pp(_transmission.concretion_, 0);
       if (_i_ > 1) render(_R_PAREN);
    }
    else     if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Transcription)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Transcription _transcription = (com.biosimilarity.reflection.model.paratrope.Absyn.Transcription) foo;
       if (_i_ > 1) render(_L_PAREN);
       render("*");
       pp(_transcription.nominal_, 0);
       if (_i_ > 1) render(_R_PAREN);
    }
    else     if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Termination)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Termination _termination = (com.biosimilarity.reflection.model.paratrope.Absyn.Termination) foo;
       if (_i_ > 1) render(_L_PAREN);
       render("0");
       if (_i_ > 1) render(_R_PAREN);
    }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.Abstraction foo, int _i_)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Suspension)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Suspension _suspension = (com.biosimilarity.reflection.model.paratrope.Absyn.Suspension) foo;
       if (_i_ > 0) render(_L_PAREN);
       pp(_suspension.formals_, 0);
       render("->");
       pp(_suspension.processexpr_, 0);
       if (_i_ > 0) render(_R_PAREN);
    }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.Concretion foo, int _i_)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Provision)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Provision _provision = (com.biosimilarity.reflection.model.paratrope.Absyn.Provision) foo;
       if (_i_ > 0) render(_L_PAREN);
       pp(_provision.actuals_, 0);
       if (_i_ > 0) render(_R_PAREN);
    }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.Nominal foo, int _i_)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.AtomLiteral)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.AtomLiteral _atomliteral = (com.biosimilarity.reflection.model.paratrope.Absyn.AtomLiteral) foo;
       if (_i_ > 0) render(_L_PAREN);
       pp(_atomliteral.ident_, 0);
       if (_i_ > 0) render(_R_PAREN);
    }
    else     if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Encoding)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Encoding _encoding = (com.biosimilarity.reflection.model.paratrope.Absyn.Encoding) foo;
       if (_i_ > 0) render(_L_PAREN);
       render("@");
       render("<");
       pp(_encoding.processexpr_, 0);
       render(">");
       if (_i_ > 0) render(_R_PAREN);
    }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.Formals foo, int _i_)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Obligation)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Obligation _obligation = (com.biosimilarity.reflection.model.paratrope.Absyn.Obligation) foo;
       if (_i_ > 0) render(_L_PAREN);
       render("(");
       pp(_obligation.listnominal_, 0);
       render(")");
       if (_i_ > 0) render(_R_PAREN);
    }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.Actuals foo, int _i_)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Remittance)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Remittance _remittance = (com.biosimilarity.reflection.model.paratrope.Absyn.Remittance) foo;
       if (_i_ > 0) render(_L_PAREN);
       render("(");
       pp(_remittance.listprocessexprplus_, 0);
       render(")");
       if (_i_ > 0) render(_R_PAREN);
    }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExprPlus foo, int _i_)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Value)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Value _value = (com.biosimilarity.reflection.model.paratrope.Absyn.Value) foo;
       if (_i_ > 0) render(_L_PAREN);
       pp(_value.processexpr_, 0);
       if (_i_ > 0) render(_R_PAREN);
    }
    else     if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Variable)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Variable _variable = (com.biosimilarity.reflection.model.paratrope.Absyn.Variable) foo;
       if (_i_ > 0) render(_L_PAREN);
       pp(_variable.nominal_, 0);
       if (_i_ > 0) render(_R_PAREN);
    }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.ListProcessExprPlus foo, int _i_)
  {
     for (java.util.Iterator<ProcessExprPlus> it = foo.iterator(); it.hasNext();)
     {
       pp(it.next(), 0);
       if (it.hasNext()) {
         render(",");
       } else {
         render("");
       }
     }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.ListProcessExpr foo, int _i_)
  {
     for (java.util.Iterator<ProcessExpr> it = foo.iterator(); it.hasNext();)
     {
       pp(it.next(), 0);
       if (it.hasNext()) {
         render(",");
       } else {
         render("");
       }
     }
  }

  private static void pp(com.biosimilarity.reflection.model.paratrope.Absyn.ListNominal foo, int _i_)
  {
     for (java.util.Iterator<Nominal> it = foo.iterator(); it.hasNext();)
     {
       pp(it.next(), 0);
       if (it.hasNext()) {
         render(",");
       } else {
         render("");
       }
     }
  }


  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExpr foo)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Composition)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Composition _composition = (com.biosimilarity.reflection.model.paratrope.Absyn.Composition) foo;
       render("(");
       render("Composition");
       render("[");
       sh(_composition.listprocessexpr_);
       render("]");
       render(")");
    }
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Reception)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Reception _reception = (com.biosimilarity.reflection.model.paratrope.Absyn.Reception) foo;
       render("(");
       render("Reception");
       sh(_reception.nominal_);
       sh(_reception.abstraction_);
       render(")");
    }
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Transmission)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Transmission _transmission = (com.biosimilarity.reflection.model.paratrope.Absyn.Transmission) foo;
       render("(");
       render("Transmission");
       sh(_transmission.nominal_);
       sh(_transmission.concretion_);
       render(")");
    }
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Transcription)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Transcription _transcription = (com.biosimilarity.reflection.model.paratrope.Absyn.Transcription) foo;
       render("(");
       render("Transcription");
       sh(_transcription.nominal_);
       render(")");
    }
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Termination)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Termination _termination = (com.biosimilarity.reflection.model.paratrope.Absyn.Termination) foo;
       render("Termination");
    }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.Abstraction foo)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Suspension)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Suspension _suspension = (com.biosimilarity.reflection.model.paratrope.Absyn.Suspension) foo;
       render("(");
       render("Suspension");
       sh(_suspension.formals_);
       sh(_suspension.processexpr_);
       render(")");
    }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.Concretion foo)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Provision)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Provision _provision = (com.biosimilarity.reflection.model.paratrope.Absyn.Provision) foo;
       render("(");
       render("Provision");
       sh(_provision.actuals_);
       render(")");
    }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.Nominal foo)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.AtomLiteral)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.AtomLiteral _atomliteral = (com.biosimilarity.reflection.model.paratrope.Absyn.AtomLiteral) foo;
       render("(");
       render("AtomLiteral");
       sh(_atomliteral.ident_);
       render(")");
    }
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Encoding)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Encoding _encoding = (com.biosimilarity.reflection.model.paratrope.Absyn.Encoding) foo;
       render("(");
       render("Encoding");
       sh(_encoding.processexpr_);
       render(")");
    }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.Formals foo)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Obligation)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Obligation _obligation = (com.biosimilarity.reflection.model.paratrope.Absyn.Obligation) foo;
       render("(");
       render("Obligation");
       render("[");
       sh(_obligation.listnominal_);
       render("]");
       render(")");
    }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.Actuals foo)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Remittance)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Remittance _remittance = (com.biosimilarity.reflection.model.paratrope.Absyn.Remittance) foo;
       render("(");
       render("Remittance");
       render("[");
       sh(_remittance.listprocessexprplus_);
       render("]");
       render(")");
    }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.ProcessExprPlus foo)
  {
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Value)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Value _value = (com.biosimilarity.reflection.model.paratrope.Absyn.Value) foo;
       render("(");
       render("Value");
       sh(_value.processexpr_);
       render(")");
    }
    if (foo instanceof com.biosimilarity.reflection.model.paratrope.Absyn.Variable)
    {
       com.biosimilarity.reflection.model.paratrope.Absyn.Variable _variable = (com.biosimilarity.reflection.model.paratrope.Absyn.Variable) foo;
       render("(");
       render("Variable");
       sh(_variable.nominal_);
       render(")");
    }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.ListProcessExprPlus foo)
  {
     for (java.util.Iterator<ProcessExprPlus> it = foo.iterator(); it.hasNext();)
     {
       sh(it.next());
       if (it.hasNext())
         render(",");
     }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.ListProcessExpr foo)
  {
     for (java.util.Iterator<ProcessExpr> it = foo.iterator(); it.hasNext();)
     {
       sh(it.next());
       if (it.hasNext())
         render(",");
     }
  }

  private static void sh(com.biosimilarity.reflection.model.paratrope.Absyn.ListNominal foo)
  {
     for (java.util.Iterator<Nominal> it = foo.iterator(); it.hasNext();)
     {
       sh(it.next());
       if (it.hasNext())
         render(",");
     }
  }


  private static void pp(Integer n, int _i_) { buf_.append(n); buf_.append(" "); }
  private static void pp(Double d, int _i_) { buf_.append(d); buf_.append(" "); }
  private static void pp(String s, int _i_) { buf_.append(s); buf_.append(" "); }
  private static void pp(Character c, int _i_) { buf_.append("'" + c.toString() + "'"); buf_.append(" "); }
  private static void sh(Integer n) { render(n.toString()); }
  private static void sh(Double d) { render(d.toString()); }
  private static void sh(Character c) { render(c.toString()); }
  private static void sh(String s) { printQuoted(s); }
  private static void printQuoted(String s) { render("\"" + s + "\""); }
  private static void indent()
  {
    int n = _n_;
    while (n > 0)
    {
      buf_.append(" ");
      n--;
    }
  }
  private static void backup()
  {
     if (buf_.charAt(buf_.length() - 1) == ' ') {
      buf_.setLength(buf_.length() - 1);
    }
  }
  private static void trim()
  {
     while (buf_.length() > 0 && buf_.charAt(0) == ' ')
        buf_.deleteCharAt(0); 
    while (buf_.length() > 0 && buf_.charAt(buf_.length()-1) == ' ')
        buf_.deleteCharAt(buf_.length()-1);
  }
  private static int _n_ = 0;
  private static StringBuilder buf_ = new StringBuilder(INITIAL_BUFFER_SIZE);
}

